﻿@model IQueryable<Website>
@{
    ViewBag.Title = "Website".Localize();
}
@functions{
    string GetHostLinks(string hosts)
    {
        var builder = new System.Text.StringBuilder("<ul>");
        var list = Json.Decode<List<string>>(hosts);
        foreach (var host in list)
        {
            builder.AppendFormat("<li><a href=\"http://{0}\">{0}</a></li>", host);
        }
        builder.Append("</ul>");

        return builder.ToString();
    }
}
<h2>
    @("Website".Localize())</h2>
@Html.Partial("HomeTabs")
<div class="toolbar">
    @Html.ActionLink("Create".Localize(), "Create", "Website", null, new { @class = "button" })
    @Html.ActionLink("Import".Localize(), "Import", "Website", null, new { @class = "button" })
</div>
@{
    var grid = new WebGrid(Model);
}
@using (Html.BeginForm("Delete", "Website"))
{
    @grid.GetHtml(
        tableStyle: "data-table",
        columns: grid.Columns(
                grid.Column("Id", "Id".Localize()),
                grid.Column("Name", "Name".Localize()),
                grid.Column("CreateTime", "CreateTime".Localize()),
                grid.Column("IsOnline", "IsOnline".Localize(), format: (item) => Html.ActionLink("IsOnline", "ToggleOnline", "Website", new { id = item.Id, returnUrl = Request.RawUrl }, new { @class = item.IsOnline.ToString().ToLower() })),
                grid.Column(header: "Hosts".Localize(), format: (item) => Html.Raw(GetHostLinks(item.Hosts))),
                grid.Column(header: "Export".Localize(), format: (item) => Html.ActionLink("Export".Localize(), "Export", "Website", new { id = item.Id }, new { @class = "export" })),
                grid.Column(header: "Edit".Localize(), format: (item) => Html.ActionLink("Edit".Localize(), "Edit", "Website", new { id = item.Id, returnUrl = Request.RawUrl }, new { @class = "edit" })),
                grid.Column(header: "Delete".Localize(), format: (item) => Html.Raw(string.Format("<button type=\"submit\" name=\"id\" value=\"{0}\" class=\"delete\">{1}</button>", item.Id, "Delete".Localize())))
        )
   )
} 